home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / telecomm / misc / linkz88.lha / LinkZ88 / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-13  |  4.3 KB  |  196 lines

  1. /*********************************************
  2.  **************    main.c   ******************
  3.  *********************************************/
  4.  
  5. #define INTUI_V36_NAMES_ONLY
  6.  
  7. #include <exec/exec.h>
  8. #include <workbench/startup.h>
  9. #include <graphics/gfxbase.h>
  10. #include <graphics/displayinfo.h>
  11. #include <intuition/screens.h>
  12. #include <libraries/amigaguide.h>
  13. #include <workbench/workbench.h>
  14. #include <devices/serial.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/alib_protos.h>
  21. #include <clib/amigaguide_protos.h>
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. #include "windows.h"
  27.  
  28. #include "consts.h"
  29. #include "structs.h"
  30. #include "protos.h"
  31.  
  32. /* Set up the version string */
  33.  
  34. char *versionstring="$VER:"VERSION_SHORTNAME" "VERSION_NUMBER" "VERSION_NUMDATE;
  35.  
  36. struct Library *IntuitionBase = NULL;
  37. struct Library *IconBase = NULL;
  38. struct Library *GadToolsBase = NULL;
  39. struct Library *AslBase = NULL;
  40. struct Library *CxBase = NULL;
  41. struct Library *WorkbenchBase = NULL;
  42.  
  43. prj_p prj = NULL;
  44.  
  45. int main(int argc, char **argv)
  46. {
  47.     struct IntuiMessage *imsg;
  48.     struct IntuiMessage curr_imsg;
  49.     struct Message *msg;
  50.  
  51.     ULONG signal_main;
  52.     ULONG signal_serial;
  53.  
  54.     ULONG signals_returned;
  55.  
  56.     BOOL done = FALSE;
  57.  
  58.     /***   Open Libraries   ***/
  59.  
  60.     if (!(IntuitionBase = OpenLibrary("intuition.library",VERSION_OS)))
  61.         cleanup();
  62.  
  63.     if (!(IconBase = OpenLibrary("icon.library",VERSION_OS)))
  64.         error("Can't open v37+ of the icon library",ERROR_FATAL,
  65. __LINE__,__FILE__);
  66.  
  67.     if (!(GadToolsBase = OpenLibrary("gadtools.library",VERSION_OS)))
  68.         error("Can't open v37+ of the gadtools library",ERROR_FATAL,
  69. __LINE__,__FILE__);
  70.  
  71.     /* Try and open version 38 of the ASL library first. */
  72.  
  73.     if (!(AslBase = OpenLibrary("asl.library",VERSION_OS)))
  74.         error("Can't open v37+ of the ASL library",ERROR_FATAL,
  75. __LINE__,__FILE__);
  76.  
  77.     if (!(WorkbenchBase = OpenLibrary("workbench.library",VERSION_OS)))
  78.         error("Can't open v37+ of the Workbench library",ERROR_FATAL,
  79. __LINE__,__FILE__);
  80.  
  81.     /***   Allocate main project structure ***/
  82.  
  83.     prj = (prj_p)AllocMem(sizeof(struct project),MEMF_CLEAR);
  84.  
  85.     if (!prj)
  86.         error("Can't allocate main project structure",ERROR_FATAL,
  87. __LINE__,__FILE__);
  88.  
  89.     /***   Set up defaults etc...   ***************************************/
  90.  
  91.     /* Set up project structure and read tooltypes */
  92.  
  93.         startup(argc,argv);
  94.  
  95.     /***   Main program   *************************************************/
  96.  
  97.     /* Open main window */
  98.  
  99.     if (OpenWindowmainwin())
  100.         error("Can't open main window",ERROR_FATAL,__LINE__,__FILE__);
  101.  
  102.     /***   Main events loop   *********************************************/
  103.  
  104.     /* Construct the signals */
  105.  
  106.     signal_main = 1L << mainwin->UserPort->mp_SigBit;
  107.     signal_serial = 1L << prj->serial_msg_port->mp_SigBit;
  108.  
  109.     while (!done) {
  110.  
  111.         /* Wait for a message from the correct ports */
  112.  
  113.         signals_returned = Wait(signal_main | signal_serial);
  114.  
  115.         /* Window message */
  116.  
  117.         if (signals_returned & signal_main) {
  118.             /* Process message */
  119.  
  120.             while (imsg = (struct IntuiMessage *)GT_GetIMsg(
  121. mainwin->UserPort)) {
  122.                 CopyMem(imsg,&curr_imsg,
  123. sizeof(struct IntuiMessage));
  124.  
  125.                 GT_ReplyIMsg((struct IntuiMessage *)imsg);
  126.  
  127.                 done = win_idcmphandler(&curr_imsg);
  128.             }
  129.         }
  130.  
  131.         /* Serial message */
  132.  
  133.         if (signals_returned & signal_main) {
  134.             /* Throw away serial stuff here */
  135.  
  136.             while (msg = GetMsg(prj->serial_msg_port))
  137.                 ReplyMsg(msg);
  138.         }
  139.     }
  140.  
  141.     /***   Exit and cleanup   *********************************************/
  142.  
  143.     cleanup();
  144.  
  145.     return(0);
  146. }
  147.  
  148. /*
  149. Function : void cleanup()
  150. Purpose : Deallocates all memory, closes all libraries etc...
  151. */
  152.  
  153. void cleanup()
  154. {
  155.     /* Close window */
  156.  
  157.     CloseWindowmainwin();
  158.  
  159.     if (prj) {
  160.         /* Closedown serial device */
  161.  
  162.         if (prj->serial_open)
  163.             CloseDevice((struct IORequest *)prj->serialio);
  164.  
  165.         if (prj->serialio)
  166.             DeleteExtIO((struct IORequest *)prj->serialio);
  167.  
  168.         /* Remove serial message port */
  169.  
  170.         if (prj->serial_msg_port)
  171.             DeletePort(prj->serial_msg_port);
  172.  
  173.         /* Last of all, deallocate project structure */
  174.  
  175.         FreeMem((void *)prj,sizeof(struct project));
  176.     }
  177.  
  178.     if (WorkbenchBase)
  179.         CloseLibrary((struct Library *)WorkbenchBase);
  180.  
  181.     if (AslBase)
  182.         CloseLibrary((struct Library *)AslBase);
  183.  
  184.     if (GadToolsBase)
  185.         CloseLibrary((struct Library *)GadToolsBase);
  186.  
  187.     if (IconBase)
  188.         CloseLibrary((struct Library *)IconBase);
  189.  
  190.     if (IntuitionBase)
  191.         CloseLibrary((struct Library *)IntuitionBase);
  192.  
  193.     exit(0);
  194. }
  195.  
  196.